package office.action.hr;

import java.util.List;
import javax.annotation.Resource;
import current.security.user.manager.service.UserManagerService;
import office.action.hr.form.CarriageEntryForm;
import office.service.hr.ICarriageEntryService;
import office.service.hr.ICarriageManageService;
import platform.common.action.BaseAction;
import platform.util.Util;

public class CarriageEntryAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ICarriageEntryService carriageEntryService;
	private CarriageEntryForm objctForm;
	private String id;
	@SuppressWarnings("unchecked")
	private List wrapperList;
	private String carriageId;
	@SuppressWarnings("unchecked")
	private List userList;
	@SuppressWarnings("unchecked")
	private List carriageList;		//可用车辆集合
	@Resource
	private UserManagerService userManagerService;
	private ICarriageManageService carriageManageService;

	public String carriageEntryList()throws Exception{
		wrapperList = carriageEntryService.getCarriageEntryList(getUserId());
		return "showList";
	}
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoAdd()throws Exception{
		//TODO 根据角色获取用户列表
		this.gotoUserList();
		return "gotoEdit";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEdit()throws Exception{
		//TODO 根据角色获取用户列表
		this.gotoUserList();
		objctForm = carriageEntryService.getById(id);
		return "gotoEdit";
	}
	
	public void gotoUserList()throws Exception{
		this.setUserList(userManagerService.getUserByRoleAndCompany("xzrsjl",getUserCompanyId()));
	}
	/**
	 * 添加或编辑数据
	 * @return
	 * @throws Exception
	 */
	public String editData() throws Exception{
		try {
			//TODO
			objctForm.setEntryUser(getUserId());
			carriageEntryService.editCarriageEntry(objctForm);
			if(null==objctForm.getId() || ("").equals(objctForm.getId())){
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			}else{
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 初始化可用操作
	 * @return
	 * @throws Exception
	 */
	public String gotoEditXml()throws Exception{
		objctForm = carriageEntryService.getById(id);
		return "editXml";
	}
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoDel()throws Exception{
		return "gotoDel";
	}
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoCheck()throws Exception{
		String state = Util.parsePropertiesReturnStr("office", "carriageSate.0").split(",")[0];//可用状态
		carriageList = carriageManageService.getCarriageManageByState(state);
		return "gotoCheck";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delData()throws Exception{
		try {
			carriageEntryService.deleteById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	
	public String checkData()throws Exception{
		try {
			carriageEntryService.checkById(id,carriageId);
			this.getAjaxMessagesJson().setMessage(true, "", "审批成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	public ICarriageEntryService getCarriageEntryService() {
		return carriageEntryService;
	}
	public void setCarriageEntryService(ICarriageEntryService carriageEntryService) {
		this.carriageEntryService = carriageEntryService;
	}
	public CarriageEntryForm getObjctForm() {
		return objctForm;
	}
	public void setObjctForm(CarriageEntryForm objctForm) {
		this.objctForm = objctForm;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@SuppressWarnings("unchecked")
	public List getWrapperList() {
		return wrapperList;
	}
	@SuppressWarnings("unchecked")
	public void setWrapperList(List wrapperList) {
		this.wrapperList = wrapperList;
	}
	public String getCarriageId() {
		return carriageId;
	}
	public void setCarriageId(String carriageId) {
		this.carriageId = carriageId;
	}
	@SuppressWarnings("unchecked")
	public List getUserList() {
		return userList;
	}
	@SuppressWarnings("unchecked")
	public void setUserList(List userList) {
		this.userList = userList;
	}
	public UserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	@SuppressWarnings("unchecked")
	public List getCarriageList() {
		return carriageList;
	}
	@SuppressWarnings("unchecked")
	public void setCarriageList(List carriageList) {
		this.carriageList = carriageList;
	}
	public ICarriageManageService getCarriageManageService() {
		return carriageManageService;
	}
	public void setCarriageManageService(
			ICarriageManageService carriageManageService) {
		this.carriageManageService = carriageManageService;
	}
	
}
